﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class news_ModuleCalendar : BasePage
{
   
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            bd();
        }
    }

    /// <summary>
    /// 加载绑定
    /// </summary>
    public void bd()
    {
        CMSModel.CMSEntities dal = DAL.DBManager.GetCmsEmtity();
        //下拉列表框年
        var times = dal.ModuleCalendar.Select(x => x.ctime.Year).Distinct().ToList();
        ddlYears.DataSource = times;
        ddlYears.DataBind();
        //下拉列表框月
        var months = dal.ModuleCalendar.Select(x => x.ctime.Month).Distinct().ToList();
        ddlMonth.DataSource = months;
        ddlMonth.DataBind();

        ddlYears.SelectedValue = times[0].ToString();      //下拉列表框年默认值
        ddlMonth.SelectedValue = months[0].ToString();      //下拉列表框月默认值
        int year = Convert.ToInt32(ddlYears.SelectedValue);
        int month = Convert.ToInt32(ddlMonth.SelectedValue);
        //板块数据绑定
        rptModuleCalendar.DataSource = dal.ModuleCalendar.Where(x => x.ctime.Year == year && x.ctime.Month == month);
        rptModuleCalendar.DataBind();
    }
    /// <summary>
    /// 下拉列表框年索引更新后板块绑定改变
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ddlYears_SelectedIndexChanged(object sender, EventArgs e)
    {
        int year = Convert.ToInt32(ddlYears.SelectedValue);
        CMSModel.CMSEntities dal = DAL.DBManager.GetCmsEmtity();
        rptModuleCalendar.DataSource = dal.ModuleCalendar.Where(x=>x.ctime.Year==year);
        rptModuleCalendar.DataBind();
    }
    /// <summary>
    /// 下拉列表框月索引更新后板块绑定改变
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ddlMonth_SelectedIndexChanged(object sender, EventArgs e)
    {
        int year = Convert.ToInt32(ddlYears.SelectedValue);
        int month = Convert.ToInt32(ddlMonth.SelectedValue);
        CMSModel.CMSEntities dal = DAL.DBManager.GetCmsEmtity();
        rptModuleCalendar.DataSource = dal.ModuleCalendar.Where(x =>x.ctime.Year==year && x.ctime.Month == month );
        rptModuleCalendar.DataBind();
    }
}